﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.COMM;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord.Queries;
namespace Mang24k99.Business.COMM
{
    public partial class BKtCommTreemenu
    {
        /// <summary>
        /// Creates the before.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>if true Cancel</returns>
        private static bool CreateBefore(MKtCommTreemenu model)
        {
            return false;
        }

        /// <summary>
        /// Creates the after.
        /// </summary>
        /// <param name="model">The model.</param>
        private static void CreateAfter(MKtCommTreemenu model)
        {

        }
        /// <summary>
        /// Updates the before.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>if true Cancel</returns>
        private static bool UpdateBefore(MKtCommTreemenu model)
        {
            return false;
        }
        /// <summary>
        /// Updates the after.
        /// </summary>
        /// <param name="model">The model.</param>
        private static void UpdateAfter(MKtCommTreemenu model)
        {

        }

        /// <summary>
        /// Deletes the before.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>if true Cancel</returns>
        private static bool DeleteBefore(MKtCommTreemenu model)
        {
            return false;
        }
        /// <summary>
        /// Deletes the after.
        /// </summary>
        /// <param name="model">The model.</param>
        private static void DeleteAfter(MKtCommTreemenu model)
        {
        }

        public static void Create(MKtCommTreemenu model)
        {
            model.IsValidate = 1;
            model.InputTime = DateTime.Now;
            bool isCancel = CreateBefore(model);
            if (isCancel)
            {
                return;
            }
            model.Create();
            CreateAfter(model);
        }
        public static void Update(MKtCommTreemenu model)
        {
            model.ModifyTime = DateTime.Now;
            bool isCancel = UpdateBefore(model);
            if (isCancel)
            {
                return;
            }
            model.Update();
            UpdateAfter(model);
        }
        public static void Delete(MKtCommTreemenu model)
        {
            //删除默认字段在ondelete中执行
            bool isCancel = DeleteBefore(model);
            if (isCancel)
            {
                return;
            }
            model.Delete();
            DeleteAfter(model);
        }

        public static IList<MKtCommTreemenu> FindAll()
        {
            ICriterion[] criteria = new ICriterion[]
            {
                //Expression.Eq("IsValidate",1),
            };
            return MKtCommTreemenu.SelectAll(criteria);
        }

        public static MKtCommTreemenu Find(object ID)
        {
            return MKtCommTreemenu.SelectByPrimaryKey(ID);
        }
        public static MKtCommTreemenu FindOne()
        {
            ICriterion[] criteria = new ICriterion[]
            {
            };
            return MKtCommTreemenu.SelectOne(criteria);
        }
        public static MKtCommTreemenu FindFirst()
        {
            ICriterion[] criteria = new ICriterion[]
            {
            };
            return MKtCommTreemenu.SelectFirst(criteria);
        }

        public static IList<MKtCommTreemenu> FindALLByProperty(string property, object value)
        {
            return MKtCommTreemenu.SelectALLByProperty(property, value);
        }

        public static IList<MKtCommTreemenu> FindALLSliced(int firstResult, int maxResult,int treeno)
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("MKtCommTreeconfig.TreeNO",treeno),
                //Expression.Eq("IsValidate",1),
            };
            return MKtCommTreemenu.SelectALLSliced(firstResult, maxResult, criteria);
        }
        public static IList<MKtCommTreemenu> FindALLQuery(int firstResult, int maxResult)
        {
            string strHql = @"Select MKtCommTreemenu"
                          + " from"
                          + " MKtCommTreemenu MKtCommTreemenu, MKtCommTreeconfig MKtCommTreeconfig"
                          + " where"
                          //+ " MKtCommTreemenu.IsValidate = 1"
                          + "  MKtCommTreemenu.MKtCommTreeconfig.TreeNO = MKtCommTreeconfig.TreeNO"
                          ;
            SimpleQuery query = new SimpleQuery(typeof(MKtCommTreemenu), strHql);
            query.SetQueryRange(firstResult, maxResult);
            return MKtCommTreemenu.SelectAllQuery(query);
        }
        public static int Count(int treeno)
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("MKtCommTreeconfig.TreeNO",treeno),
                //Expression.Eq("IsValidate",1),
            };
            return MKtCommTreemenu.Counts(criteria);
        }
        public static bool Exists(object id)
        {
            return MKtCommTreemenu.Exist(id);
        }
    }
}
